<template>
  <div class="set-container c21">
    <h4>添加账号</h4>
    <div class="mt30">
      <p>
        账号<el-input placeholder="请输入账号" v-model="account"></el-input>
      </p>
      <p>
        密码
        <el-input
          placeholder="请输入密码"
          v-model="pwd"
          show-password
        ></el-input>
      </p>
      <p>
        用户组
        <el-select v-model="value" placeholder="请选择用户组">
          <el-option label="超级管理员" value="超级管理员"> </el-option>
          <el-option label="普通管理员" value="普通管理员"> </el-option>
        </el-select>
      </p>

      <p class="tac">
        <el-button
          :disabled="dis"
          style="background-color: #666699"
          class="fff"
          @click="cliadd"
          >确定</el-button
        >
        <el-button class="ml15 fff" type="danger">重置</el-button>
      </p>
    </div>
  </div>
</template>

<script>
import { useradd } from "@/apis/users";
export default {
  data() {
    return {
      value: "普通管理员",
      account: "",
      pwd: "",
      dis: false,
    };
  },
  methods: {
    cliadd() {
      if (this.account == "" || this.pwd == "") {
        this.$message({
          type: "warning",
          message: "请完整填写信息!",
          center: true,
        });
      } else {
        this.dis = true;
        setTimeout(() => {
          this.dis = false;
        }, 1000);
        useradd({
          account: this.account,
          password: this.pwd,
          userGroup: this.value,
        }).then((res) => {
          if (res.data.code == 0) {
            this.$message({
              message: "恭喜你，账号添加成功!",
              type: "success",
              center: true,
            });
          } else {
            this.$message.error({
              message: "添加账号失败,请重新操作!",
              center: true,
            });
          }
        });
      }
    },
  },
};
</script>

<style lang="less" scoped>
.set-container {
  box-shadow: 0 0 15px 1px #ccc;
  padding-bottom: 40px;
  background-color: #fff;
  border-radius: 5px;
  h4 {
    line-height: 75px;
    padding: 0 20px;
    border-bottom: 1px solid #ccc;
  }
  div {
    width: 450px;
    text-align: right;
    p {
      .el-input,
      .el-select {
        margin: 0 0 30px 15px;
        width: 300px;
      }
    }
  }
}
</style>